package com.yanqu.road.server.cmd.activity.summergames.fromcross;

import com.yanqu.road.entity.enums.eMailType;
import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SummerGamesProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.logic.mail.MailManager;
import com.yanqu.road.server.manger.MultipleLanguageMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.server.protocol.Protocol;
import io.netty.channel.ChannelHandlerContext;

import java.util.Date;

@Cmd(code = Protocol.S_SUMMER_GAMES_AUTO_CANCEL_APPLY, desc = "活动结束自动返还奖杯")
public class SummerGamesAutoCancelApplyCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage yanQuMessage) throws Exception {
        SummerGamesProto.CrossSummerGamesAutoCancelApplySync sync = SummerGamesProto.CrossSummerGamesAutoCancelApplySync.parseFrom(yanQuMessage.getBytes());

        String language = "";
        UserInfo userInfo = UserMgr.getUserInfo(sync.getUserId());
        if(userInfo != null){
            language = userInfo.getLanguage();
        }
        String mailTitle = MultipleLanguageMgr.getContent(MailManager.SUMMER_GAMES_MAIL_TITLE_6, language);
        String mailContent = MultipleLanguageMgr.getContent(MailManager.SUMMER_GAMES_CONTENT_6, language);
        //邮件奖励
        MailManager.sendMail(sync.getUserId(), 0, eMailType.SYSTEM.getValue(), sync.getReward(), mailContent, mailTitle, new Date());
    }


}
